import 'dart:convert' show json;

import '../user.dart';

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }

  return null;
}

class MineInformation {
  MineInformation({
    this.id,
    this.like_num,
    this.follow_num,
    this.comment_num,
    this.is_follow,
    this.is_likes,
    this.user,
  });

  factory MineInformation.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : MineInformation(
        id: asT<int>(jsonRes['id']),
        like_num: asT<int>(jsonRes['like_num']),
        follow_num: asT<int>(jsonRes['follow_num']),
        comment_num: asT<int>(jsonRes['comment_num']),
        is_follow: asT<int>(jsonRes['is_follow']),
        is_likes: asT<int>(jsonRes['is_likes']),
        user: User.fromJson(asT<Map<String, dynamic>>(jsonRes['user'])),
      );

  int id;
  int like_num;
  int follow_num;
  int comment_num;
  int is_follow;
  int is_likes;
  User user;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'id': id,
    'like_num': like_num,
    'follow_num': follow_num,
    'comment_num': comment_num,
    'user': user,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

